#include<stdio.h>
#include<stdlib.h>
#include <string.h>
struct friends{    	  	    
    char name[20];
    char phone[12];
    struct friends*next;
}    	  	    *head; //1
void creat();
void show();
void sel(char name[]);
int main()
{    	  	    
    creat();//1
    show(); //1
    char name[20];//1
    printf("请输入要查找联系人姓名：\n");//1
    scanf("%s",name);//1
    sel(name);//2
    return 0;
}    	  	    
void  creat()//2
{    	  	    
    struct friends *q ,*tail; //1
    char flag = 'Y';
    head = (struct friends *)malloc(sizeof(struct friends));
    head->next = NULL; 
    tail = head;
    while(flag=='Y')//1
    {    	  	    
        printf("请依次输入每个联系人姓名，电话： \n");
        q = (struct friends *)malloc(sizeof(struct friends));//1
        q->next = NULL;//1
        scanf("%s %s",q->name,q->phone);//1
        tail->next = q;//1
        tail = q;//1
        printf("是否继续输入,按Y键继续输入，其他键就结束.\n");
        getchar();
        flag = getchar();//1
      }
 
}    	  	    
void show() //2
{    	  	    
    printf("输出所有联系人信息为:姓名 电话\n");
    struct friends *out;//1
        out = head->next;//1
    while(out)//1
    {    	  	    
    printf("%s %s\n", out->name,out->phone);//1
    out = out->next; 
         
    }
}    	  	    
//查询联系人信息
void sel(char name[]) //2
{    	  	    
    struct friends *p;//1
    int flag = 0;
    p = head->next;
    while(p)//1
    {    	  	    
        if(strcmp(p->name,name)==0)//1
        {    	  	    
            flag = 1;//1
            break;
        }
        p=p->next;//1
    }
    if(flag)//1
    {    	  	    
        printf("该联系人的姓名：%s 电话：%s   \n",p->name, p->phone);//1
    }
    else//1
    {    	  	    
        printf("不存在此联系人\n");
    }
 
}    	  	    
 
void Free()  //2
{    	  	    
    struct friends *p = head, *pr = NULL;//1
    while (p != NULL)//1
    {    	  	    
        pr = p;
        p = p->next;//1
        free(pr);//1
    }
}    	  	